# -*- coding: UTF-8 -*-


from .x2mbase import X2mBase
import copy


class X2mTreeBase(X2mBase):
    def __init__(self, field_info,  **kwargs):
        super().__init__(field_info, **kwargs)


class X2mTree(X2mTreeBase):
    def __init__(self, field_info,  **kwargs):
        super().__init__(field_info, type='tree', **kwargs)

    def read(self, ids):
        Model = self.Model
        fields = self.fields_list
        return Model.read(ids, fields=fields)

    def commit(self, records, values, value):
        # todo merge tuples
        values_ret = [] + values + [value]

        return {
            'values': values_ret,
            'values_onchange': values_ret
        }
